package com.jinxin.platform.cdzxkacs.rpc;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

/**
 * All rights Reserved, Designed By www.beonelot.com
 *
 * @version: V1.0
 * @Copyright: www.beonelot.com Inc. All rights reserved.
 * @Description：
 * @Date:
 * @Author: Lingnan
 **/
public class Test {
    public static void main(String[] args) {
        // {"1":[6,8,7],"3":[7],"4":[10],"6":[11]}
        List<Integer> timeSlotList = new ArrayList<>();
        timeSlotList.add(0);
        timeSlotList.add(1);
        timeSlotList.add(3);
        timeSlotList.add(5);
        timeSlotList.add(6);
        timeSlotList.add(22);
        timeSlotList.add(23);
        Collections.sort(timeSlotList);
        JSONArray jsonArr2 = new JSONArray();
        for (int i = 0; i < timeSlotList.size(); i++) {
            int begin = timeSlotList.get(i);
            int end = begin;
            int step = 0;
            if(timeSlotList.contains((begin+1))){
                for (int j = i+1; j < timeSlotList.size(); j++) {
                    int b = timeSlotList.get(j);
                    if((b-end==1)){
                        end = b;
                        step++;
                    }else {
                        break;
                    }
                }
            }
            i = i + step;
            JSONObject p5JsonObj = new JSONObject();
            p5JsonObj.put("Begin",parseTimeSlot(begin)+":00:00");
            p5JsonObj.put("End",parseTimeSlot(end)+":59:59");
            p5JsonObj.put("ArmingType",0); //默认定时类型
            jsonArr2.add(p5JsonObj);
        }
        System.out.println(jsonArr2.toJSONString());
    }
    private static String parseTimeSlot(int num){
        if(num < 10){
            return "0"+num;
        }else if(num >= 24){
            return "00";
        }else {
            return num+"";
        }
    }

}
